package ink.lovejinhu.acwing.baseAl;

import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * @author jinhu
 * created 2021-07-08 17:20
 */
public class MergeSort {
    /**
     * 1.确立分界点 mid=(l+r)/2
     * <p>
     * 2.递归排序
     * <p>
     * 3.归并合二为一
     * <p>
     * //简单来说，归并排序等于递归加上两个有序数组进行合并为一个有序数组
     *
     * @param q
     * @param left
     * @param right
     */
    public static void merge_sort(int q[], int left, int right) {
        if (left >= right) return;

        int mid = (left + right) / 2;   //找分界点

        merge_sort(q, left, mid);   //递归左边
        merge_sort(q, mid + 1, right);  //递归右边

        int k = 0, i = left, j = mid + 1;
        int[] tmp = new int[right - left + 1];

        while (i <= mid && j <= right) {   //两个有序数组合并
            if (q[i] <= q[j]) {
                tmp[k++] = q[i++];
            } else {
                tmp[k++] = q[j++];
            }
        }

        while (i <= mid) {
            tmp[k++] = q[i++];
        }
        while (j <= right) {
            tmp[k++] = q[j++];
        }

        for (i = left, j = 0; i <= right; i++, j++) {
            q[i] = tmp[j];
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }

        merge_sort(arr, 0, n - 1);

        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }


}
